/**
 * @author JackGao
 *			email:jackgao.china@gmail.com
 *  date：2016-6-23
 * 
 */
package cn.cuit.ds.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.cuit.ds.dao.IGoodsDao;
import cn.cuit.ds.dao.IOrderDetailDao;
import cn.cuit.ds.dao.IShopperinfoDao;
import cn.cuit.ds.dao.impl.GoodsDao;
import cn.cuit.ds.dao.impl.OrderDetailDao;
import cn.cuit.ds.dao.impl.ShopperinfoDao;
import cn.cuit.ds.domain.Goods;
import cn.cuit.ds.domain.OrderDeatil;
import cn.cuit.ds.domain.Shopper;
import cn.cuit.ds.service.IShopperService;
import cn.cuit.ds.utils.OtherUtils;

@Service(value="ShopperService")
public class ShopperService implements IShopperService {

	@Resource(name="ShopperinfoDao")
	public IShopperinfoDao shopperinfoDao ;
	public void setShopperinfoDao(IShopperinfoDao shopperinfoDao) {
		this.shopperinfoDao = shopperinfoDao;
	}
	
	@Resource(name="GoodsDao")
	IGoodsDao goodsDao;
	public void setGoodsDao(IGoodsDao goodsDao) {
		this.goodsDao = goodsDao;
	}
	
	@Resource(name="OrderDetailDao")
	IOrderDetailDao orderDetailDao ;
	public void setOrderDetailDao(IOrderDetailDao orderDetailDao) {
		this.orderDetailDao = orderDetailDao;
	}
	
	
	
	
	
	public int regist(Shopper shopper) {
		shopper.setShoperId(OtherUtils.getUUID());
		shopper.setRegistTime(OtherUtils.getDate());
		shopperinfoDao.add(shopper);
		return 1;
	}

	public Shopper login(Shopper shopper) {
		System.out.println(shopperinfoDao==null);
		return shopperinfoDao.findByNameAndPwd(shopper.getShopName(), shopper.getPwd());

	}

	public void addGoods(Goods goods) {
		goods.setGoodsId(OtherUtils.getUUID());
		goods.setTimeAdd(OtherUtils.getDate());
		goods.setGoodsNum("0");
		goodsDao.add(goods);
		
	}

	public List<Goods> getAllGoods(String shopperId) {
		return goodsDao.getAllByShopperId(shopperId);
	
	}

	public void deleteGoods(String goodsId) {
		// TODO Auto-generated method stub
		goodsDao.deleteByGoodsId(goodsId);
	}

	public void updateGoods(Goods goods) {
		goodsDao.update(goods);
	}

	public Goods getById(String goodsId) {
		return goodsDao.findById(goodsId);
	}

	public List<OrderDeatil> getAllOrderDetail(String shopperId) {
		return orderDetailDao.getAllDetailByShopperId(shopperId);
	}





	public void changeState(String ordersId) {
		// TODO Auto-generated method stub
		orderDetailDao.changeState(ordersId);
	}

	

}
